import time
from argparse import Action

from selenium import webdriver
from selenium.webdriver import ActionChains


def f1(browser):
    url = 'https://www.mogu.com/'
    browser.get(url)
    time.sleep(2)
    # 获取网页的内容
    html = browser.page_source
    # 获取当前网址
    current_url = browser.current_url
    print(current_url)
    # 使用selenium自带的xpath方法解析
    imgs = browser.find_elements_by_xpath('//div[@class="waterfall-wrap"]//div[@class="cp-brandTopic-image lazy-image aspect-fill width-long"]/img')
    print(imgs)
    for img in imgs:
        # 获取节点对应属性
        print(img.get_attribute('src'))
        # 获取节点的左上角位置
        print(img.location)
        # 获取节点的宽高
        print(img.size)



    # 根据文字内容获取链接节点
    # a = browser.find_element_by_link_text('我的订单')
    # a.click()
    # time.sleep(5)

    # 根据部分文字获取链接节点
    elements = browser.find_element_by_partial_link_text('订单')
    for element in elements:
        print(element.text)

def f2(browser):
    url = "https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable"
    browser.get(url)
    browser.switch_to.frame('iframeResult')
    src_element = browser.find_element_by_id('draggable')
    dest_element = browser.find_element_by_id('droppable')

    # 动作链(完成一堆动作)
    actions = ActionChains(browser)
    # 拖拽动作
    actions.drag_and_drop(src_element,dest_element)
    # 执行动作链
    actions.perform()

    time.sleep(3)
def main():
    #打开浏览器
    browser = webdriver.Chrome()
    #f1(browser)
    f2(browser)


if __name__ == '__main__':
    main()